package wyp.library.ui.listview;

import java.util.ArrayList;

import android.content.Context;
import android.widget.BaseAdapter;

public abstract class WypListViewAdapter<T> extends BaseAdapter {

	public ArrayList<T> dataList = new ArrayList<T>();
	protected Context context;

	public WypListViewAdapter(Context _context) {
		this.context = _context;
	}

	public WypListViewAdapter(Context _context, ArrayList<T> _data) {
		this(_context);
		this.dataList = _data;
	}
	
	public void addData(ArrayList<T> _dataList){
		for(T _t : _dataList){
			this.dataList.add(_t);
		}
		this.notifyDataSetChanged();
	}

	public void setData(ArrayList<T> _dataList) {
		this.dataList = _dataList;
		this.notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		try {
			return dataList.size();
		} catch (Exception e) {
			return 0;
		}
	}

	@Override
	public T getItem(int _position) {
		try {
			return dataList.get(_position);
		} catch (Exception e) {
			return null;
		}
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

}
